package com.framework.core.sqlfactory.sqlmapperproxyfactory;

import java.lang.reflect.Method;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

//生成Cglib动态代理（class）
public class SqlMapperCglibProxy implements MethodInterceptor {

	@Override
	public Object intercept(Object o, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
		System.err.println("++++++before " + methodProxy.getSuperName() + "++++++");
		System.err.println(method.getName());
		methodProxy.invokeSuper(o, args);
		// Object object =
		System.err.println("++++++before " + methodProxy.getSuperName() + "++++++");
		return "hello";
	}

	// 获取生成代理实例
	public Object getProxyInstance(Class<?> clazz) {

		Enhancer enhancer = new Enhancer();
		enhancer.setSuperclass(clazz);
		enhancer.setCallback(this);

		return enhancer.create();

	}
}
